package karileet.meeting.profile.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;
import karileet.meeting.profile.ProfileConf;
import karileet.meeting.profile.SoundManager;
 
/**
 * Class overrides broadcastreceiver onreceive method and plays notification 
 * sound when app is enabled. 
 * 
 * @author markus karileet
 */
public class CallReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		String intentState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
		ProfileConf state = new ProfileConf(context);
		if (intentState.equals(TelephonyManager.EXTRA_STATE_RINGING) && state.isProfileEnabled()) {
			Log.d(ProfileConf.APP, "Recieved call, playing sound");
			SoundManager sm = new SoundManager(context);
			//set sound to max
	    	sm.play(state.getBeepVolume()); //Dependent of music, video & other media volume setting
	    	//set sound to old value
		}
	}
}